<?php
    require_once("connect.php");
	
	function getHierarchies(){
		global $dbcon;
		return pg_query($dbcon, "SELECT * FROM hierarchies ORDER BY id");
	}
	
	function getHierarchy($idparam){
		global $dbcon;
		
		$id = (integer)$idparam;
		$query = "SELECT * FROM hierarchies WHERE id = $id";
		
		$resulthandler = pg_query($dbcon, $query);
		return pg_fetch_assoc($resulthandler);
	}
		
	function printHierarchiesAsOptions($idparam){
		$id = NULL;
		if(isset($idparam)){
			$id = (integer)$idparam;
		}
		$resulthandler = getHierarchies();
		while($hierarchy = pg_fetch_assoc($resulthandler)){
			if($hierarchy["id"] == $id){
				echo "<option value=\"".$hierarchy['id']."\" selected>".$hierarchy['name']."</option>";
			}
			else{
				echo "<option value=\"".$hierarchy['id']."\">".$hierarchy['name']."</option>";
			}
		}
	}
?>